<!-- 考试模块-在线考试 -->
<template>
  <page-layout>
    <!-- 列表页面 -->
    <a-row :gutter="[10, 10]">
      <!-- 查询条件 -->
      <a-col :span="24">
        <a-card>
          <pro-query
            :searchParam="searchParam"
            @on-search="search"
          >
            <template #test="{ data }">
              <a-input v-model:value="data.test" type="text"/>
            </template>
          </pro-query>
        </a-card>
      </a-col>
      <!-- 用户列表 -->
      <a-col :span="24">
        <a-card>
          <pro-table
            ref="tableRef"
            :fetch="fetch"
            :columns="columns"
            :toolbar="toolbar"
            :operate="operate"
            :param="state.param"
            :pagination="pagination"
            :row-selection="{ selectedRowKeys: state.selectedRowKeys, onChange: onSelectChange }">
          </pro-table>
        </a-card>
      </a-col>
    </a-row>
<!--     详情页面 -->
<!--    <info :visible="state.visibleInfo" @close="closeInfo" :record="state.recordInfo"></info>-->
  </page-layout>
</template>

<script>
import {onlinePaging} from "@/api/module/exam.js";
import {createVNode, reactive, ref, toRaw} from 'vue';
import {message} from "_ant-design-vue@2.2.8@ant-design-vue";
import { useRouter } from 'vue-router';
const removeKey = "remove";
const removeBatchKey = "removeBatch";

export default {
  components: {
    // info,
  },
  setup() {
    const tableRef = ref();
    const router = useRouter();


    /// 查询用户
    const fetch = async (param) => {
      var response = await onlinePaging(param);
      return {
        total: response.data.total,
        data: response.data.records,
      };
    };


    /// 行操作
    const operate = [
      {
        label: "asd",event: function (record) {
          console.log("-----record-----",record.id)
          if (record.aa == 0) {
            let toRaw1 = toRaw(record);
            if(toRaw1.openType == 1){
                toRaw1.openType = '完全开放'
            }else if(toRaw1.openType == 2){
              toRaw1.openType = '定向考试'
            }
            router.push({
              path:'/preview/index',
              query:{
                id:JSON.stringify(toRaw1)
              }
            })
          } else if (record.aa == 1) {
            message.error("该试卷已禁用！！！")
          } else if (record.aa == 2) {
            message.error("该试卷还未开始！！！")
          } else if (record.aa == 3) {
            message.error("该试卷已结束！！！")
          }
        },takeExam:'true'
      }
    ];

    /// 考试类型转换格式
    const converFormat = [{label: "完全开放", value: 1}, {label: "定向考试", value: 2}];

    /// 配置
    const columns = [
      {dataIndex: "title", key: "title", title: "考试名称"},
      {dataIndex: "openType", key: "openType", title: "考试类型" , conver: converFormat},
      {dataIndex: "timeList", key: "timeList", title: "考试时间" },
      {dataIndex: "totalTime", key: "totalTime", title: "考试时长/分钟" },
      {dataIndex: "totalScore", key: "totalScore", title: "考试总分"},
      {dataIndex: "qualifyScore", key: "qualifyScore", title: "及格线"},
    ];

    /// 分页参数
    const pagination = {current: 1, size: 10}

    /// 外置参数
    const state = reactive({
      selectedRowKeys: [],
      param: {},
      record: {},
      visibleSave: false,
      visibleEdit: false,
      visibleGive: false,
      visibleInfo: false,
      recordEdit: {},
      recordGive: {},
      recordInfo: {},
    })

    /// 查询参数  //需要改
    const searchParam = [
      {key: "name", type: "input", label: "开放类型"},
      {key: "code", type: "input", label: "搜索考试名称"},
    ]

    /// 选择操作
    const onSelectChange = selectedRowKeys => {
      state.selectedRowKeys = selectedRowKeys;
    };

    /// 查询操作
    const search = function (value) {
      state.param = value;
      tableRef.value.reload();
    }

    /// 关闭新增
    const closeSave = function () {
      state.visibleSave = false;
      tableRef.value.reload();
    }

    /// 关闭修改
    const closeEdit = function () {
      state.visibleEdit = false;
      tableRef.value.reload();
    }

    /// 关闭分配
    const closeGive = function () {
      state.visibleGive = false;
      tableRef.value.reload();
    }

    /// 关闭详情
    const closeInfo = function () {
      state.visibleInfo = false;
    }


    return {
      state,
      fetch,
      search,
      toolbar,
      columns,
      operate,
      pagination,
      searchParam,
      onSelectChange,

      closeSave,
      closeEdit,
      closeGive,
      closeInfo,

      tableRef
    };
  },
};
</script>
